#ifndef RPM_H_
#define RPM_H_
#include <stdint.h>
#include <stdio.h>
#include <sys/types.h>

#include "md5.h"

#include "rpm_tags.h"

#ifndef RPMFILE_DEFINED
#define RPMFILE_DEFINED 1
/**
 *  Contains information about an open RPM file.
 *  This is the public interface.  The private interface
 *  is in rpm_priv.h.
 */
typedef struct
{
    void * priv;
} RpmFile;

#endif

typedef enum {
    rpmNotAUri = -11,
    rpmStsDatabaseLockError= -10,
    rpmStsDatabaseNotFound = -9,
    rpmStsDatabaseReadError = -8,
    rpmStsRpmInconsistencyErr = -7,         /**< The RPM file was internally inconsistent. */
    rpmStsWriteError = -6,
    rpmStsReadErr = -5,                     /**< Could not read from disk. */
    rpmStsInvalidHandleErr = -4,            /**< A bad/corrupt handle was passed to the API. */
    rpmStsNotAnRpm = -3,                        /**< The opened file was not an RPM. */
    rpmStsFileNotFoundErr = -2,             /**< The file was not found. */
    rpmStsUnknownErr = -1,                     /**< Some other error occurred. */
    rpmStsNoError = 0                       /**< Function completed successfully. */
} RpmStatus;

/**
 *  Useful typedefs.
 */
typedef  RpmFile* RpmFileHandle;

RpmFileHandle
OpenRpmFile( const char * pathToRpm, RpmStatus * retVal );

int
rpm_getNumTags ( RpmFileHandle handle );

RpmHeaderElementType
GetHeaderTagType ( RpmFileHandle handle, RpmTag theTag, int * count );

char *
rpm_getTagValueAsString ( RpmFileHandle handle, RpmTag theTag );

void
GetHeaderTagAsStringArray( RpmFileHandle handle, RpmTag theTag, char *** ptrToStringArray, int * numElements );

void
FreeStringArray( char ** stringArray, int numElements );

void *
GetHeaderTagAsPointer( RpmFileHandle handle, RpmTag theTag, RpmHeaderElementType * elementType, int * count );

void
ListArchiveContents( RpmFileHandle handle, FILE * out );

void
ExtractScriptContents( RpmFileHandle handle, RpmScript script, int includeShebang, FILE * out );

typedef void file_setup_callback ( const char * name, const char * asInstalled, int fd, void * userData );

void
ExtractArchiveContents( RpmFileHandle handle, const char * root, file_setup_callback * callback, void * userData );

int
QueryFormat( RpmFileHandle handle, const char * queryFormat, FILE * out, FILE * errOut );

int
RecursiveMakeDirectories( const char * directory );

RpmTag
GetHeaderTagFromString( const char * str );

RpmStatus
CloseRpmFile( RpmFileHandle fileToClose );

#endif /*RPM_H_*/

